const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    /**
     * 募兵
     */
    @property(cc.Prefab)
    recruitmentPreFab: cc.Prefab = null;
    /**
     * 升级
     */
    @property(cc.Prefab)
    upgradePreFab: cc.Prefab = null;
    /**
     * 详情
     */
    @property(cc.Prefab)
    detailPreFab: cc.Prefab = null;

    onLoad () {

    }

    start () {

    }

    update (dt) {

    }

    /**
     * 建筑被点击展示操作按钮
     * @param e
     * @param d
     */
    showButtons(e,d){
        let clickNode=e.target;
        let tx = e.getLocationX();
        let ty = e.getLocationY();
        let fictitiousNode=clickNode.convertToNodeSpaceAR(cc.v2(tx,ty));
        if(clickNode.childrenCount>0){
            clickNode.children.forEach(v=>v.destroy());
        }
        let recruitmentPreFabNode = cc.instantiate(this.recruitmentPreFab);
        let upgradePreFabNode = cc.instantiate(this.upgradePreFab);
        let detailPreFabNode = cc.instantiate(this.detailPreFab);
        recruitmentPreFabNode.x=fictitiousNode.x;
        recruitmentPreFabNode.y=fictitiousNode.y-80;
        upgradePreFabNode.x=recruitmentPreFabNode.x+70;
        upgradePreFabNode.y=recruitmentPreFabNode.y+30;
        detailPreFabNode.x=recruitmentPreFabNode.x-70;
        detailPreFabNode.y=recruitmentPreFabNode.y+30;
        clickNode.addChild(recruitmentPreFabNode);
        clickNode.addChild(upgradePreFabNode);
        clickNode.addChild(detailPreFabNode);
    }
}
